import java.util.*;

public class Demo10 {


    //注意输入输子是0的时候，还有注意负数的转换，负数的转换其他进制就是取反然后按正数那样的转换，最后再加一个负号

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int M = in.nextInt();
        int n = in.nextInt();
        if (M==0){
            System.out.println("0");
            return;
        }
        String table = "0123456789ABCDEF";
        StringBuilder s = new StringBuilder();
        boolean flag = false;
        if (M<0){
            M = -M;
            flag = true;
        }
        while (M!=0){
            s.append(table.charAt(M%n));
            M/=n;
        }
        if(flag==true){
            s.append("-");
        }
        s.reverse();
        System.out.println(s);

    }


   /* public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int M = in.nextInt();
        int n = in.nextInt();
        char[] arr = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
        String ret = "";
        while (M>0){
            ret+=arr[M%n];
            M/=n;
        }
        for(int i=ret.length()-1;i>=0;i--){
            System.out.print(ret.charAt(i));
        }
    }*/


/*    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int A = (a+c)/2;
        int B1 = (c-a)/2;
        int B2 = (b+d)/2;
        int C = (d-b)/2;
        if (B1!=B2){
            System.out.println("No");
        }else{
            System.out.println(A + " "+B1 +" "+C);
        }


    }*/














/*
    private static int n;
    private static int count;
    private static int sum = 0;
    private static int cau = 1;
    private static String path = "";
    private static int max = Integer.MAX_VALUE;
    private static HashMap<String,Integer> hash= new HashMap<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i<n;i++){
            arr[i] = in.nextInt();
        }

        //排序
        Arrays.sort(arr);
        dfs(arr,0);
        System.out.println(count);

    }

    private static void dfs(int[] arr, int x) {

        path+=arr[x];
        sum =(sum%max + arr[x])%max;
        cau = (cau%max * arr[x])%max;
        if (sum>cau && hash.getOrDefault(path,0)==0){
            count++;
            hash.put(path,1);
        }
        if(x==n){
            return;
        }
        for(int i=x+1;i<n;i++){
            dfs(arr,i);
            sum-=arr[i];
            cau/=arr[i];
            path = path.substring(0,path.length()-1);
        }

    }*/


/*    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int y = in.nextInt();
        int m = in.nextInt();
        int d = in.nextInt();
        int ret = 0;
        int[] month = {0,31,28,31,30,31,30,31,31,30,31,30,31};
        if ((y%4==0&&y%100!=0)||y%400==0){
            month[2] = 29;
        }
        for(int i=1;i<m;i++){
            ret+=month[i];
        }
        ret+=d;
        System.out.println(ret);


    }*/










    /*static int count;
    static int min;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        int m = in.nextInt();
        min = Integer.MAX_VALUE;
        List<Integer> common = new ArrayList<>();
        commonInt(24,common);
        int k = common.get(0);
        common.remove(0);
        dfs(4,24-k,common);
        System.out.println(min);



    }

    private static void dfs(int n, int m, List<Integer> common) {
        count++;
        if (m<n){
            return;
        }
        if (common.size()==0 && m==n){
            min = Math.min(min,count);
            return;
        }

        //求m的最大公约数，存到common数组中，然后递归下去
        List<Integer> commons = new ArrayList<>();
        commonInt(m,commons);

        int k = commons.get(0);
        commons.remove(0);
        dfs(n,m-k,commons);

    }

    private static void commonInt(int m, List<Integer> common) {
        for(int i=2;i<m;i++){
            if (m%i==0 && m/i>=i){
                if (m/i!=i){
                    common.add(i);
                    common.add(m/i);
                }else {
                    common.add(i);
                }
            }
        }

    }*/




    /*public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String tmp = "";
        int isChar = 0;
        int count = 0;
        List<String> list = new ArrayList<>();
        for(int i=0;i<str.length();i++){
            if (str.charAt(i)=='\"'){
                if (isChar==1){
                    isChar--;
                    continue;
                }
                isChar++;
            }

            if (isChar==0 && str.charAt(i) == ' '){
                count++;
                list.add(tmp);
                tmp="";
                continue;
            }
            if (str.charAt(i) !='\"'){
                tmp+=str.charAt(i);
            }

        }
        list.add(tmp);
        System.out.println(count+1);
        for (String s:list){
            System.out.println(s);
        }

    }*/



}
